home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / misc / prtfolio / sft.arj / SSEN_UX.I < prev    next >
Text File  |  1992-07-16  |  5KB  |  275 lines

  1. /*---------------------------------------------------------------------*/
  2.  
  3. /*
  4.   SSEN_UX.C  : sendingg file via terminal line
  5.                compatible to bruce carbreys sreceive/ssend
  6.                and sft for msdos systems
  7.  
  8.                System: MINIX, Coherent; ibm-aix, sun
  9.  
  10.                R. Henze   01.04.91
  11.                last edit: 15.07.92
  12. */
  13.  
  14. #define rest  0 
  15. //#define minix 1
  16. #define aix   2
  17.  
  18. //system festlegen:
  19.  
  20. #define systm aix
  21.  
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <sgtty.h>
  25. #if (systm == aix)
  26. #include <termio.h>              /*tty*/
  27. #endif
  28. #include <time.h>                        /*zeitumrechnungen*/
  29. #include "/usr/include/sys/stat.h"
  30.  
  31. #define bufsz       0x0200
  32. #define max_retry   5
  33. #define nak         0x15
  34. #define ack         0x06
  35. #define enq         0x05
  36.  
  37. #define esc 0x1b
  38. #define true 1
  39. #define false 0
  40. #define cr 0x0d
  41. #define lf 0x0a
  42.  
  43. #define f1 0xbb
  44.  
  45. unsigned char bcheck;
  46. unsigned char checksum;
  47. unsigned char retry;
  48. unsigned short blksz;
  49. unsigned short bnum;
  50. unsigned short blknum;
  51. unsigned char dummy;
  52. unsigned char chr;
  53. unsigned char buf[bufsz];
  54. unsigned char outbuf[bufsz*2];
  55. unsigned char ib;
  56.  
  57. int file;
  58. unsigned short i;
  59.  
  60. int input_fd = 0;
  61.  
  62. unsigned char chr;
  63. unsigned char ib;
  64.  
  65. struct sgttyb old_tty;
  66. struct sgttyb new_tty;
  67.  
  68. #if (systm == aix)
  69. struct termio  old_tmio;
  70. struct termio  new_tmio;
  71. #endif
  72.  
  73. time_t fdtime;            /*long*/
  74.  
  75. struct stat filestat;
  76.  
  77. int flag;
  78. /*---------------------------------*/
  79.  
  80. void quit()
  81. {
  82. close(file);
  83. exit(1);
  84. }
  85.  
  86. /*---------------------------------*/
  87.  
  88. unsigned char get_com()
  89. {
  90. unsigned char chr;
  91.  
  92. read(input_fd,&chr,1);
  93. return(chr);
  94. }
  95.  
  96. /*---------------------------------*/
  97.  
  98. int send_com(chr)
  99. unsigned char chr;
  100.  
  101. {
  102. if (write(input_fd, &chr, 1))
  103.   return(true);
  104. else
  105.   return(false);
  106. }
  107.  
  108. /*---------------------------------*/
  109.  
  110. void put_com(chr)
  111. unsigned char chr;
  112. {
  113. while (!send_com(chr))
  114.   ;
  115. }
  116.  
  117. /*---------------------------------*/
  118.  
  119. void put_com_chk(chr)
  120. unsigned char chr;           /* output byte, update checksum*/
  121. {
  122. checksum = checksum ^ chr;
  123. put_com(chr);
  124. }
  125.  
  126. /*---------------------------------*/
  127.  
  128. void out_blk()
  129.  
  130. /* output block number blknum to port*/
  131. /* buf holds data*/
  132. /* blksz is size of block, 0 for eof*/
  133.  
  134. {
  135. unsigned char ib;
  136. unsigned short k;
  137.  
  138. if ( blksz > 0)
  139.   k=0;
  140.   i=0;
  141.   while (k<blksz)
  142.     if (flag == true)
  143.       if (buf[k] == lf)
  144.         outbuf[i] = cr;
  145.         i++;
  146.     outbuf[i] = buf[k];
  147.     k++;
  148.     i++;
  149.   blksz = i;
  150.  
  151. retry = 0;
  152. do
  153.   checksum=0;
  154.  
  155.   ib = (unsigned char) (blknum & 0x00ff);
  156.   put_com_chk(ib);
  157.   ib = (unsigned char) ((blknum>>8) & 0x00ff);
  158.   put_com_chk(ib);
  159.  
  160.   ib = (unsigned char) (blksz & 0x00ff);
  161.   put_com_chk(ib);
  162.   ib = (unsigned char) ((blksz>>8) & 0x00ff);
  163.   put_com_chk(ib);
  164.  
  165.   if ( blksz > 0)
  166.     for (i=0; i<blksz; i++)
  167.       put_com_chk(outbuf[i]);
  168.  
  169.   put_com(checksum);
  170.  
  171.   do
  172.     chr = get_com();
  173.   while (chr != ack && chr != nak);
  174.  
  175.   if (chr==ack)
  176.     return;
  177.   retry=retry+1;
  178. while (retry < max_retry);
  179. quit();
  180.  
  181. }
  182.  
  183. /* ------------------------------------------------------------------------ */
  184.  
  185. void putftimdat()
  186. {
  187. put_com(' ');
  188. put_com(' ');
  189. put_com(' ');
  190. put_com(' ');
  191. put_com(' ');
  192. put_com(' ');
  193. }
  194.  
  195. /* ------------------------------------------------------------------------ */
  196.  
  197. void main(argc,argv)
  198. int argc;
  199. char *argv[];
  200.  
  201. {
  202. if (argc < 2)
  203.   exit(1);
  204.  
  205. flag = false;
  206. if (argc>2)
  207.   if (*(argv[2]) == 'a')
  208.     flag = true;
  209.  
  210. ioctl(input_fd,TIOCGETP,&old_tty);
  211. ioctl(input_fd,TIOCGETP,&new_tty);
  212.  
  213. new_tty.sg_flags = new_tty.sg_flags | RAW;             /* RAW */
  214. #ifdef minix
  215. new_tty.sg_flags = new_tty.sg_flags | BITS8;           /* 8 bit */
  216. #endif
  217. new_tty.sg_flags = new_tty.sg_flags & (ECHO ^ 0xffff); /* no ECHO */
  218. new_tty.sg_flags = new_tty.sg_flags & (CRMOD ^ 0xffff); /*no lf to crlf*/
  219. new_tty.sg_flags = new_tty.sg_flags & (XTABS ^ 0xffff); /*no tab expansion*/
  220.  
  221. ioctl(input_fd,TIOCSETP,&new_tty);
  222.  
  223. #if (systm == aix)
  224. ioctl(input_fd,TCGETA,&old_tmio);
  225. ioctl(input_fd,TCGETA,&new_tmio);
  226. new_tmio.c_oflag = new_tmio.c_oflag & (ONLCR ^ 0xffff); /* no Outp-NLCR-mapping*/
  227. new_tmio.c_iflag = new_tmio.c_iflag & (ICRNL ^ 0xffff); /* no Input-CRNL-mapping*/
  228. ioctl(input_fd,TCSETA,&new_tmio);
  229. #endif
  230.  
  231. file = open(argv[1],0);
  232. if (file == -1)
  233.   quit();
  234.  
  235. put_com(f1); 
  236.  
  237. do
  238.   chr = get_com();
  239. while(chr != ack);
  240.  
  241. i = 0;
  242. do
  243.   put_com(*(argv[1]+i));
  244.   i++;
  245. while (*(argv[1]+i-1) != 0);
  246.  
  247. do
  248.   chr = get_com();
  249. while(chr != ack);
  250.  
  251. putftimdat();
  252. do
  253.   chr = get_com();
  254. while(chr != ack);
  255.  
  256. blknum = 0;                                /* block sequence #*/
  257. do
  258.   blksz = read(file,buf,bufsz);
  259.   blknum++;
  260.   out_blk();
  261. while (blksz != 0);
  262. printf("\nfile successfully transmitted!");
  263.  
  264. close(file);
  265.  
  266. #if (systm == aix)
  267. ioctl(input_fd,TCSETA,&old_tmio);
  268. #endif
  269.  
  270. ioctl(input_fd,TIOCSETP,&old_tty);
  271.  
  272. }
  273.  
  274. /*---------------------- end of file ssen_mx.i -----------------------------*/
  275.